﻿using Castle.DynamicProxy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Xwy.Practical.AOPS
{
    public abstract class BaseInterceptorAttribute : Attribute
    {
        public abstract Action Do(IInvocation invocation ,Action action);       
    }

    public class LogBeforAttribute : BaseInterceptorAttribute
    {
        public override Action Do(IInvocation invocation,Action action)
        {
            return () =>
            {
                Console.WriteLine("LogBeforAttribute start");
                action.Invoke();
                Console.WriteLine("LogBeforAttribute end");
            };      
        }
    }
    
    public class LogingAttribute : BaseInterceptorAttribute
    {
        public override Action Do(IInvocation invocation, Action action)
        {
            return () =>
            {
                Console.WriteLine("LogingAttribute start");
                action.Invoke();
                Console.WriteLine("LogingAttribute end");
            };
        }
    }

    public class LogAfterAttribute : BaseInterceptorAttribute
    {
        public override Action Do(IInvocation invocation, Action action)
        {
            return () =>
            {
                Console.WriteLine("LogAfterAttribute start");
                action.Invoke();
                Console.WriteLine("LogAfterAttribute end");
            };

        }
    }

}
